from selenium import webdriver
import time
import csv

# 浏览器后台静默执行
# chrome_options = webdriver.ChromeOptions()
# chrome_options.add_argument('--headless')
wd = webdriver.Chrome()

# 初始化
wd.get("http://172.16.60.131")
wd.maximize_window()
wd.implicitly_wait(10)

wd.find_element_by_xpath("//../span[text() = '用户中心登录']").click()

#
def login(email, passwd):
    # 输入邮箱
    wd.find_element_by_xpath("//input[@placeholder= '邮箱']").send_keys(email)
    # 输入密码
    wd.find_element_by_xpath("//input[@placeholder = '密码']").send_keys(passwd)
    # 点击“授权并登录”按钮
    wd.find_element_by_xpath("//span[text() = '授权并登录']").click()
    wd.find_element_by_xpath("//span[@class= 'f-fs-16 f-m-r-10']").click()
    time.sleep(0.5)
    wd.find_element_by_xpath("//div[@title = '登出']").click()
    wd.find_element_by_xpath("//../span[text() = '用户中心登录']").click()
    wd.find_element_by_link_text("账号密码登录").click()

with open('user.csv', 'r', encoding='utf-8') as f:
    f_csv = csv.DictReader(f)
    for i in f_csv:
        email = i['email']
        passwd = i['passwd']
        login(email, passwd)

wd.close()